#!/usr/bin/env bash
# yitong.bai@qq.com

# 禁用系统SELinux
function DisableSELinuxIfNotDisabled() {
  if [[ ! "$(sestatus | grep "SELinux status:" | awk '{print $3}')" = "disabled" ]];
  then
    sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
    setenforce 0
  fi
}

function DisableFirewalldIfNotDisabled() {

  [ ! -f "/usr/sbin/firewalld" ] && return 0

  systemctl stop firewalld > /dev/null
  systemctl disable firewalld > /dev/null 
}

# 将系统自带的yum配置文件备份，放到bak/目录下
function BackupPkgManagementConfiguration() {
  mkdir -p /etc/yum.repos.d/bak
  if ls /etc/yum.repos.d/*.repo &> /dev/null;
  then
    mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
  fi
  rm -fr /var/cache/yum
}

# 配置一个Yum源
function ConfigurePkgManagementConfiguration() {
  local name="${1}"
  local url="${2}"
  cat > /etc/yum.repos.d/"${name}".repo <<EOF
[${name}]
name=${name}
enabled=1
baseurl=${url}
gpgcheck=0
EOF
}
